package com.android.tianyuanyouxuan.ui.activity;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;

import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.android.tianyuanyouxuan.base.BaseActivity;
import com.android.tianyuanyouxuan.databinding.ActivityMessageBinding;
import com.android.tianyuanyouxuan.presenter.MessageActivityPresenter;
import com.android.tianyuanyouxuan.ui.adapter.MessageActivityAdapter;

/**
 * 消息
 */
public class MessageActivity extends BaseActivity {

    private ActivityMessageBinding viewBinding;

    private MessageActivityPresenter presenter = new MessageActivityPresenter();

    // 给谁发消息
    private String sendUser;

    private MessageActivityAdapter adapter = new MessageActivityAdapter();

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        viewBinding = ActivityMessageBinding.inflate(LayoutInflater.from(this));
        setContentView(viewBinding.getRoot());
        sendUser = getIntent().getStringExtra("data");
        initTitleBar();

        viewBinding.rvMessage.setLayoutManager(new LinearLayoutManager(this));
        viewBinding.rvMessage.setAdapter(adapter);
        adapter.setNewInstance(presenter.getMessageList(sendUser));

        viewBinding.send.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String text = viewBinding.etInput.getText().toString();
                if (!TextUtils.isEmpty(text)) {
                    adapter.addData(presenter.sendMessage(text, sendUser));
                    viewBinding.etInput.setText("");
                }
            }
        });
    }

}

